﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using FastReport;

using MINERP.BLL.InnerFactory;

namespace MINERP.InnerFactory
{
    public partial class FrmPrint : Form
    {
        public FrmPrint()
        {
            InitializeComponent();
        }


        private void FrmPrint_Load(object sender, EventArgs e)
        {

        }

        private void FrmPrint_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Enter)
            {
                Print();
            }
        }
        private string FormatProductCode()
        {

            string code = txtPhotoCode.Text.Trim();
            if (code.Length < 10)
            {
                int c = Convert.ToInt32(code);
                code = "3" + string.Format("{0:d9}", c);
            }
            txtPhotoCode.SelectAll();
            return code;
        }

        private void Print()
        {
            InnerFactoryBLL _bll = new InnerFactoryBLL();
            if (txtPhotoCode.Text.Trim() != string.Empty)
            {
                string productCode = FormatProductCode();
                if (_bll.IsPhotoExist(productCode))
                {
                    DataSet ds = _bll.GetReportdata(productCode, "");
                    ds.WriteXml(@"C:\windows\xmlData\PrintFactoryReport.xml", XmlWriteMode.WriteSchema);
                    Report fasrReport = new Report();
                    try
                    {
                        fasrReport.Load(Application.StartupPath + "\\frFactoryReport.frx");
                    }
                    catch (Exception)
                    {

                        MessageBox.Show("加载报表失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    }
                    fasrReport.Print();
                }
                else
                {
                    MessageBox.Show("没有找到该照片的信息！", "确认", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            else
            {
                MessageBox.Show("请输入照片号！", "确认", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
        private void btnOk_Click(object sender, EventArgs e)
        {
            Print();
        }
    }
}
